//
//  LGFollowDataSyptomCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//

#import "LGFollowDataInOutCell.h"

@interface LGFollowDataInOutCell()
/**   */
@property (nonatomic , strong)UIView *shadowView;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *monthLabel;
/**   */
@property (nonatomic , strong)UILabel *outTitle;
/**   */
@property (nonatomic , strong)UILabel *outLabel;
/**   */
@property (nonatomic , strong)UILabel *inTitle;
/**   */
@property (nonatomic , strong)UILabel *inLabel;
/**   */
@property (nonatomic , strong)UILabel *abdominTitle;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UILabel *valueLabel;
/**  差值 */
@property (nonatomic , strong)UIButton *differBtn;

@end

@implementation LGFollowDataInOutCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    if(dataDic.allKeys.count == 0) return;
    self.monthLabel.text = LGNSString(dataDic[@"record_date"]);
    NSString *outContent = LGNSString(dataDic[@"iodata"][@"out_content"]);
    NSString *inContent = LGNSString(dataDic[@"iodata"][@"in_content"]);
    self.outLabel.text = outContent.length>0?outContent:@" ";
    self.inLabel.text = inContent.length>0?inContent:@" ";
    NSArray *tempArray = dataDic[@"acdata"];
    if(tempArray.count > 0){
        self.timeLabel.text = LGNSString(dataDic[@"acdata"][0][@"rtime"]);
        self.valueLabel.text = LGNSString(dataDic[@"acdata"][0][@"acvalue"]);
        NSString *status = LGNSString(dataDic[@"acdata"][0][@"status"]);
        self.differBtn.hidden = NO;
        if([status isEqualToString:@"high"]){
            [self.differBtn setTitleColor:[UIColor colorWithString:@"#DB453A"] forState:UIControlStateNormal];
            [self.differBtn setImage:[UIImage imageNamed:@"腹围-上升"] forState:UIControlStateNormal];
        }else if ([status isEqualToString:@"low"]){
            [self.differBtn setTitleColor:[UIColor colorWithString:@"#2EAF71"] forState:UIControlStateNormal];
            [self.differBtn setImage:[UIImage imageNamed:@"腹围-下降"] forState:UIControlStateNormal];
        }else{
            self.differBtn.hidden = YES;
            [self.differBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        }
        [self.differBtn setTitle:LGNSString(dataDic[@"acdata"][0][@"dvalue"]) forState:UIControlStateNormal];
    }else{
        self.timeLabel.text = @"";
        self.valueLabel.text = @"";
        self.differBtn.hidden = YES;
        [self.differBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [self.differBtn setTitle:@"" forState:UIControlStateNormal];
    }
    
}


-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.shadowView];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.monthLabel];
    [self.baseView addSubview:self.outTitle];
    [self.baseView addSubview:self.outLabel];
    [self.baseView addSubview:self.inTitle];
    [self.baseView addSubview:self.inLabel];
    [self.baseView addSubview:self.abdominTitle];
    [self.baseView addSubview:self.unitLabel];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.valueLabel];
    [self.baseView addSubview:self.differBtn];
    
    [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-viewPix(5));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(viewPix(5));
    }];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    
    [self.monthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(10));
        make.left.equalTo(self.baseView).offset(viewPix(12));
    }];
    
    [self.outTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.monthLabel.mas_bottom).offset(viewPix(14));
        make.left.equalTo(self.monthLabel);
    }];
    
    [self.outLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(78));
        make.width.equalTo(@(Screen_W-viewPix(147)));
        make.top.equalTo(self.outTitle).offset(2);
    }];
    
    [self.inTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.outLabel.mas_bottom).offset(viewPix(17));
        make.left.equalTo(self.monthLabel);
    }];
    [self.inLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inTitle).offset(2);
        make.left.right.equalTo(self.outLabel);
    }];
    [self.abdominTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inLabel.mas_bottom).offset(viewPix(16));
        make.bottom.equalTo(self.baseView).offset(-viewPix(13));
        make.left.equalTo(self.outTitle);
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.abdominTitle.mas_right);
        make.bottom.equalTo(self.abdominTitle);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.outLabel);
        make.centerY.equalTo(self.abdominTitle);
    }];
    
    [self.valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeLabel.mas_right).offset(viewPix(45));
        make.centerY.equalTo(self.timeLabel);
    }];
    [self.differBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.valueLabel.mas_right);
        make.centerY.equalTo(self.valueLabel);
        make.width.equalTo(@(viewPix(60)));
        make.height.equalTo(@(viewPix(18)));
    }];
}

-(UIView *)shadowView{
    if(!_shadowView){
        _shadowView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _shadowView.backgroundColor = [UIColor whiteColor];
    }
    return _shadowView;
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#EFEFEF"];
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}


-(UILabel *)monthLabel{
    if(!_monthLabel){
        _monthLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _monthLabel.frame = CGRectMake(viewPix(12), viewPix(10), viewPix(150), viewPix(22));
    }
    return _monthLabel;
}


-(UILabel *)outTitle{
    if(!_outTitle){
        _outTitle = [UILabel lableWithText:@"出量" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _outTitle;
}

-(UILabel *)outLabel{
    if(!_outLabel){
        _outLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _outLabel;
}

-(UILabel *)inTitle{
    if(!_inTitle){
        _inTitle = [UILabel lableWithText:@"入量" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _inTitle;
}

-(UILabel *)inLabel{
    if(!_inLabel){
        _inLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _inLabel;
}




-(UILabel *)abdominTitle{
    if(!_abdominTitle){
        _abdominTitle = [UILabel lableWithText:@"腹围" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _abdominTitle;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"cm" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _unitLabel;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}


-(UILabel *)valueLabel{
    if(!_valueLabel){
        _valueLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _valueLabel;
}

-(UIButton *)differBtn{
    if(!_differBtn){
        _differBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#2EAF71" imageName:@""];
        _differBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _differBtn;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
